home *** CD-ROM | disk | FTP | other *** search
- ANIMATED SPRITES
-
- By Ian Smith
-
- There have been many articles relating to the use of Sprites on the
- Archimedes. These have covered the use of PLOT &ED,X,Y to display a
- Sprite in its defined colours at point (X,Y) and the use of a Mask to
- allow a background to appear through the 'unused' parts of a sprite.
- They have also shown the use of Exclusive OR plotting using GCOL 11,0 to
- allow the sprite to be moved over any coloured background.
-
- The EOR solution to this last problem, of moving a multi-coloured sprite
- over a multicoloured background, works BUT unless a great deal of
- thought is given to palette selection the sprite DOES NOT retain its
- defined colour during movement.
-
- Many games will require the facility to define a sprite in specified
- colours, with a mask, and to move it STILL retaining those colours
- rather than those produced by EOR.
-
- A solution is to use the standard Move/Display/Erase in a loop BUT NOT
- to use EOR. The following Algorithm does this :
-
-
- 1 Define the sprite 'MySprite' WITH a MASK (using SEDIT on the
- Welcome Disk).
-
- 2 Determine the size of 'MySprite'.
- This may be known BUT a SYS call does it for you.
-
- LOOP
-
- 3 Determine the position where 'MySprite' is to be plotted.
-
- 4 GRAB a sprite 'Temp' from the screen at this position the
- same size as 'MySprite'.
-
- 5 PLOT 'MySprite' with the mask.
-
- 6 PLOT the grabbed sprite 'Temp' to ERASE 'Mysprite'.
-
- ENDLOOP
-
- The following program demonstrates this :
-
- 10 REM > SpritePlot
- 20 REM Copyright Ian Smith
- 30 REM March 1989
- 40
- 50 REM An example program to show the use of sprites moving
- 60 REM across a multi coloured background by grabbing an area
- 70 REM of screen as a sprite and then using it to overwrite the
- 80 REM moving sprite.
- 90
- 100 MODE 15 : REM Works in others modes
- 110 T$="Temp" : REM Will be the sprite grabbed from screen
- 120 M$="MySprite" : REM A masked sprite created with SEDIT
- 130 *SLOAD !Sprites
- 140
- 150 SYS &2E,40,,T$ TO ,,,W,H : REM Find size of sprite to grab
- 160 : REM W)idth and H)eight
- 170 PROCDrawBackground : REM Draw a Multicoloured background
- 180 PROCTitle : REM and put titles on
- 190
- 200 REPEAT
- 210 REM ****** MOVE ******
- 220 MOUSE X,Y,B
- 230 SYS &2E,16,,T$,1,X,Y,X+W*2,Y+H*4 : REM Grab sprite from screen
- 240
- 250 OSCLI("SCHOOSE " + M$ ) : REM Select original sprite
- 260
- 270 REM ****** DISPLAY ******
- 280 GCOL 8,0 : REM Now plot it with its mask
- 290 PLOT &ED, X,Y : REM at the mouse position
- 300 PLOT &ED,900,800 : REM and display it in rectangle
- 310
- 320 WAIT:WAIT : REM Synchronise output
- 330
- 340 OSCLI("SCHOOSE " + T$) : REM Now plot the grabbed sprite
- 350
- 360 REM ****** ERASE ******
- 370 GCOL 0,0
- 380 PLOT &ED,X,Y : REM at the same place
- 390 PLOT &ED,1000,800 : REM and in its rectangle
- 400 UNTIL B=7 : REM 3 buttons terminates
- 410 END
- 420
- 430 DEF PROCDrawBackground
- 440 GCOL 3 : RECTANGLE FILL 0,0,300,300 : REM Just a couple of
- 450 GCOL 4 : RECTANGLE FILL 50,50,50,50 : REM rectangles and
- 460 GCOL 12: CIRCLE FILL 800,400,200 : REM circle
- 470 GCOL 5 : CIRCLE FILL 600,300,100
- 480 OSCLI("SCHOOSE " + M$)
- 490 PLOT &ED,75,90 : REM and the sprite
- 500 ENDPROC
- 510
- 520 DEF PROCTitle
- 530 GCOL 1
- 540 RECTANGLE 900-2,800-4,W*2+4,H*4+8 : REM Draw rectangles
- 550 RECTANGLE 1000-2,800-4,W*2+4,H*4+8 : REM in which sprires
- 560 PRINT TAB(53,2);"S P R I T E S" : REM are displayed
- 570 PRINT TAB(52,3);"original grabbed"
- 580 PRINT TAB(0,1);"SPRITE DEMONSTRATION : use mouse to move sprite"
- 590 ENDPROC
-
-
- Comments on the program :
-
- PROCDrawBackgound sets up a background to move over.
- PROCTitle Simply puts Text and a couple of rectangles on the screen
-
- 150 Uses a SYS call to find the Width and Height of 'MySprite'
- This is needed so that the right size 'Temp' can be grabbed.
- (See Programmers Reference Manual pp 429,433)
-
- 230 Grabs the sprite from the screen using a SYS call.
- Note the *2 and *4 to compensate for screen MODE 15
- You'll need to change this for other resolution modes.
-
- 250 Selects 'MySprite'
-
- 280 Selects the Mask Plot option GCOL 8.
-
- 290 Plots the sprite at the Mouse selected point
-
- 300 Plots the sprite in a rectangle to show its original colours.
-
- 340 Selects 'Temp'
-
- 380 Plots 'Temp' effectively erasing 'MySprite'
-
- 390 Plots 'Temp' in its rectangle.
-
- The effect of 390 has an interesting side-effect.
- When you run the program move the sprite over the rectangle ! See what
- happens !
-
- The program 'SpritePlot' and Sprite File '!Sprites' are on this month's
- disk BUT you can use the program by keying it in AND ALSO CREATING A
- MASKED SPRITE IN MODE 15 USING SEDIT SAVED AS !SPRITES.
-
- The program can obviously be modified to run in other Modes.
- The flicker on the Sprite can be removed by modifying the program to
- plot ONLY if the mouse has been moved.
-
-